package com.hc.bankonline.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hc.bankonline.services.BankOnlineRecordservices;
import com.hc.bankonline.services.BankOnlineRecordservicesImpl;

public class BankOnlineSelectServlet extends HttpServlet {

	private static final long serialVersionUID = -4204623330302214683L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		Map map = (Map)  request.getSession().getAttribute("mapAcount");
		String loginAccount =(String) map.get("loginAccount");
		
		String cardno = request.getParameter("cardno");
		
		String m = request.getParameter("money");
		double money = Double.valueOf(m);
		
		BankOnlineRecordservices bankOnlineRecordBiz = new BankOnlineRecordservicesImpl();
		
		boolean result = bankOnlineRecordBiz.insertRecordIn(money, cardno);
		boolean result1 = bankOnlineRecordBiz.insertRecordIn(money, loginAccount);
		
		if(result && result1){
			System.out.println("插入数据成功！");
			request.getRequestDispatcher("transfersuccess.jsp").forward(request, response);
			
		}else{
			System.out.println("插入数据失败！");
			request.getRequestDispatcher("transfer.jsp").forward(request, response);
		}
		
		
	}
	
}
